package com.hwadee.mapper;

import com.hwadee.pojo.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PermissionMapper {

    //查询所有权限信息
    @Select("SELECT * FROM permission")
    @Results({//使用 @Results 显式指定字段映射关系，解决数据库列名与 Java 字段名不一致的问题
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "parent_id", property = "parentId")
    })
    List<Permission> getAllPermissions();
    //为角色添加权限，向中间表 role_permission 中插入一条记录
    @Insert("INSERT INTO role_permission(role_id, permission_id) VALUES (#{roleId}, #{permissionId})")
    int addRolePermission(@Param("roleId") Integer roleId, @Param("permissionId") Integer permissionId);
}